package com.sky.mapper;

import com.sky.entity.AddressBook;
import com.sky.result.Result;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

@Mapper
@Component
public interface AddressBookMapper {

//    新增地址
    @Insert("insert into address_book (user_Id, consignee, sex, phone, province_Code, province_Name, city_Code, city_Name, district_Code, " +
            "district_Name, detail, label, is_Default ) values (#{userId}, #{consignee}, #{sex}, #{phone}, "+
            " #{provinceCode}, #{provinceName}, #{cityCode}, #{cityName}, #{districtCode}, #{districtName}, #{detail}, #{label}, #{isDefault})")
    Integer save(AddressBook addressBook);

//    查询当前登录用户的所有地址信息
    @Select("select * from address_book")
    List<AddressBook> getAll();

//    查询默认地址
    @Select("select * from address_book where is_Default = 0 and user_Id = #{id} ")
    AddressBook getDefault(Long id);

//    根据id修改地址
    @Update("update address_book set consignee =#{consignee},sex =#{sex},phone=#{phone},province_Code=#{provinceCode},province_Name=#{provinceName},city_Code=#{cityCode},city_Name=#{cityName}, district_Code=#{districtCode},district_Name=#{districtName},detail=#{detail},label=#{label} where id=#{id}")
    Integer updateById(AddressBook addressBook);

//    根据id删除地址
    @Delete("delete from address_book where id = #{id}")
    Integer deleteById(Long id);

//    根据id查询地址
    @Select("select * from address_book where id=#{id}")
    AddressBook seleteById(Long id);

//    设置默认地址
    @Update("update address_book set is_Default = #{isDefault} where id=#{id} ")
    Integer updateDefault(AddressBook addressBook);

//   根据id  是否默认地址
    @Update("update address_book set is_Default = #{isDefault} where id=#{id} ")
    Integer updateDefaultById(Long id,Integer isDefault);
}
